package kotan.view.table.editor;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComponent;
import javax.swing.JDialog;

import kotan.Kotan;
import kotan.datastore.api.Text;
import kotan.model.EntityModel;

public class TextEditorDialog {

    public static void showDialog(JComponent parentComponent, EntityModel model, int column, Text text) {
        final JDialog dialog = new JDialog(Kotan.get().getMainFrame());
        dialog.setTitle("Text editor");
        @SuppressWarnings("serial")
        final TextEditorPanel panel = new TextEditorPanel() {

            @Override
            protected void onApply() {
                super.onApply();
                dialog.dispose();
            }

            @Override
            protected void onCancel() {
                super.onCancel();
                dialog.dispose();
            }

        };
        dialog.addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                panel.applyButton.requestFocusInWindow();
            }
        });
        panel.init(model, column, text);
        dialog.add(panel);
        dialog.pack();
        dialog.setLocationRelativeTo(parentComponent);
        dialog.setVisible(true);
    }


}
